package com.ts_xiaoa.ts_android_library.widget.indicator

import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter

/**
 * create by ts_xiaoA on 2020-08-28 20:12
 * email：443502578@qq.com
 * desc：
 */
abstract class SimplePageAdapter : PagerAdapter() {

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View?)
    }

    override fun getItemPosition(`object`: Any): Int {
        return super.getItemPosition(`object`)
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val itemView = getView(container, position)
        container.addView(itemView)
        return itemView
    }

    /**
     * 创建view
     * @param container                 container
     * @param position                  索引
     * @return
     */
    abstract fun getView(container: ViewGroup?, position: Int): View

}